<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php echo $this->breadCrumbs(); ?>
  </div>
  <?php if (isset($error_warning)) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/customer.png" alt="" /> <?php echo $_['heading_title']; ?></h1>
      <div class="buttons">
	  <a onclick="$('form').attr('action', '<?php echo UA('sale/customer/approve'); ?>'); $('form').submit();" class="button"><?php echo $_['button_approve']; ?></a>
	  <a href="<?php echo UA('sale/customer/insert'); ?>" class="button"><?php echo $_['button_insert']; ?></a><a onclick="$('form').attr('action', '<?php echo UA('sale/customer/delete'); ?>'); $('form').submit();" class="button"><?php echo $_['button_delete']; ?></a></div>
    </div>
    <div class="content">
      <form action="" method="post" enctype="multipart/form-data" id="form">
        <table class="J_tablelist list" data-acturi="<?php echo UA('sale/customer/smartedit');?>">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="left">
                <a <?php echo sort_url('name'); ?>><?php echo $_['column_name']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('c.email'); ?>><?php echo $_['column_email']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('c.customer_group_id'); ?>><?php echo $_['column_customer_group']; ?></a>
               </td>
               <td class="right"><a <?php echo sort_url('c.grade'); ?>><?php echo $_['column_grade']; ?></a></td>
              <td class="left">
                <a <?php echo sort_url('c.status'); ?>><?php echo $_['column_status']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('c.approved'); ?>><?php echo $_['column_approved']; ?></a>
               </td>
              <td class="left">
                <a <?php echo sort_url('c.ip'); ?>><?php echo $_['column_ip']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('c.date_added'); ?>><?php echo $_['column_date_added']; ?></a>
              </td>
              <td class="right"><a <?php echo sort_url('c.logins'); ?>><?php echo $_['column_logins']; ?></a></td>
              <td class="right"><a <?php echo sort_url('c.orders'); ?>><?php echo $_['column_orders']; ?></a></td>
              <td class="right"><a <?php echo sort_url('c.amount'); ?>><?php echo $_['column_amount']; ?></a></td>
              <td class="right"><a <?php echo sort_url('c.points'); ?>><?php echo $_['column_points']; ?></a></td>
              <td class="right"><?php echo $_['column_action']; ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td></td>
              <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" size="15" /></td>
              <td><input type="text" name="filter_email" value="<?php echo $filter_email; ?>" size="20" /></td>
              <td><select name="filter_customer_group_id">
                  <option value="*"></option>
                  <?php echo form_select_option($customer_groups, $filter_customer_group_id, false, 'customer_group_id', 'name'); ?>
                </select></td>
              <td></td>
              <td><select name="filter_status">
                  <option value="*"></option>
                  <?php echo form_select_option($_['option_statuses'], $filter_status, true); ?>
                </select></td>
              <td><select name="filter_approved">
                  <option value="*"></option>
                  <?php echo form_select_option($_['option_yesno'], $filter_approved, true); ?>
                </select></td>
              <td><input type="text" name="filter_ip" value="<?php echo $filter_ip; ?>" size="12" /></td>
              <td><input type="text" name="filter_date_added" value="<?php echo $filter_date_added; ?>" size="10" id="date" /></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $_['button_filter']; ?></a></td>
            </tr>
          </tbody>
          <tbody class="J_tbody_cm">
            <?php if ($customers) { ?>
            <?php foreach ($customers as $customer) { ?>
            <tr onmouseover="$(this).addClass('on');" onmouseout="$(this).removeClass('on');"
				data-id="<?php echo $customer['customer_id'];?>" <?php if ($customer['style']) echo 'class="mark_style', $customer['style'], '"';?>>
              <td style="text-align: center;">
                <input type="checkbox" name="selected[]" value="<?php echo $customer['customer_id']; ?>" />
              </td>
              <td class="left"><?php echo $customer['name']; ?>
              <?php if (!empty($customer['note'])) { ?>
				  <a id="note-<?php echo $customer['customer_id']; ?>" onclick="showNoteDialog('customer', <?php echo $customer['customer_id'];?>)">
				    <img src="view/image/note.png" />
				  	<span class="none"><?php echo $customer['note'];?></span>
				  </a>
				  <?php } else { ?>
				  <a id="note-<?php echo $customer['customer_id']; ?>" onclick="showNoteDialog('customer', <?php echo $customer['customer_id'];?>)"></a>
			<?php } ?>
              </td>
              <td class="left"><span data-tdtype="edit" data-field="email" data-id="<?php echo $customer['customer_id'];?>"><?php echo $customer['email']; ?></span></td>
              <td class="left"><span data-tdtype="select" data-field="customer_group_id" data-id="<?php echo $customer['customer_id'];?>" data-source="customer_groups" data-value="<?php echo $customer['customer_group_id'];?>"><?php echo $customer['customer_group']; ?></span></td>
              <td><?php if ($customer['grade']) echo get_award_stars($customer['grade']); ?></td>
              <td class="left"><img class="cur" src="view/image/<?php echo $customer['status'] ? 'enabled' : 'disabled'; ?>.png" data-tdtype="toggle" data-field="status" data-id="<?php echo $customer['customer_id'];?>" data-value="<?php echo $customer['status']; ?>"></td>
              <td class="left"><img class="cur" src="view/image/<?php echo $customer['approved']? 'enabled' : 'disabled'; ?>.png" data-tdtype="toggle" data-field="approved" data-id="<?php echo $customer['customer_id'];?>" data-value="<?php echo $customer['approved']; ?>"/></td>
              <td class="left"><?php echo $customer['ip']; ?></td>
              <td class="left"><?php echo v5_date_format($customer['date_added']); ?></td>
              <td class="right"><a href="<?php echo UA('sale/customer_ip', 'filter_reset=1&filter_customer_id=' . $customer['customer_id']);?>"><?php echo $customer['logins']; ?></a></td>
              <td class="right"><a href="<?php echo UA('sale/order', 'filter_reset=1&customer_id=' . $customer['customer_id']);?>"><?php echo $customer['orders']; ?></a></td>
              <td class="right"><?php echo $customer['amount']; ?></td>
              <td class="right"><?php echo $customer['points']; ?></td>
              <td class="right">
                [ <a href="<?php echo UA('sale/customer/update', 'customer_id=' . $customer['customer_id']); ?>"><?php echo $_['text_edit']; ?></a> ]
              </td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="14"><?php echo $_['text_no_results']; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<div id="contextMenu" class="contextMenu">
<ul>
<li id="note"><?php echo $_['cm_add_note']; ?></li>
<li id="style1"><span class="mark_style1"><?php echo $_['cm_mark_style1']; ?></span></li>
<li id="style2"><span class="mark_style2"><?php echo $_['cm_mark_style2']; ?></span></li>
<li id="style3"><span class="mark_style3"><?php echo $_['cm_mark_style3']; ?></span></li>
<li id="style4"><span class="mark_style4"><?php echo $_['cm_mark_style4']; ?></span></li>
<li id="style5"><span class="mark_style5"><?php echo $_['cm_mark_style5']; ?></span></li>
<li id="remove">Remove Style</li>
<li><b><?php echo $_['column_login'];?></b>
<ul>
   <li id="store0"><?php echo $_['text_default']; ?></li>
     <?php foreach ($stores as $store) { ?>
   <li id="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></li>
    <?php } ?>
</ul>
</li>
</ul>
</div>
<script src="<?php echo ROOT;?>static/javascript/jquery/jquery.contextmenu.min.js"></script>
<script type="text/javascript"><!--
function filter() {
	url = '<?php echo UA('sale/customer'); ?>&filter_reset=1';
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
	
	var filter_email = $('input[name=\'filter_email\']').attr('value');
	
	if (filter_email) {
		url += '&filter_email=' + encodeURIComponent(filter_email);
	}
	
	var filter_customer_group_id = $('select[name=\'filter_customer_group_id\']').attr('value');
	
	if (filter_customer_group_id != '*') {
		url += '&filter_customer_group_id=' + encodeURIComponent(filter_customer_group_id);
	}	
	
	var filter_status = $('select[name=\'filter_status\']').attr('value');
	
	if (filter_status != '*') {
		url += '&filter_status=' + encodeURIComponent(filter_status); 
	}	
	
	var filter_approved = $('select[name=\'filter_approved\']').attr('value');
	
	if (filter_approved != '*') {
		url += '&filter_approved=' + encodeURIComponent(filter_approved);
	}	
	
	var filter_ip = $('input[name=\'filter_ip\']').attr('value');
	
	if (filter_ip) {
		url += '&filter_ip=' + encodeURIComponent(filter_ip);
	}
		
	var filter_date_added = $('input[name=\'filter_date_added\']').attr('value');
	
	if (filter_date_added) {
		url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
	}
	
	location = url;
}
//--></script>
<script type="text/javascript"><!--
$(document).ready(function() {
	$('#date').datepicker({dateFormat: 'yy-mm-dd'});
});
$('.J_tbody_cm tr').contextMenu('contextMenu', {
	bindings: {
		'note': function(tr) {showNoteDialog('customer', $(tr).attr('data-id'));},
		'style1': function(tr) {
			$(tr).addClass('mark_style1');
			markStyle('customer', $(tr).attr('data-id'), 1);
		},
		'style2': function(tr) {
			$(tr).addClass('mark_style2');
			markStyle('customer', $(tr).attr('data-id'), 2);
		},
		'style3': function(tr) {
			$(tr).addClass('mark_style3');
			markStyle('customer', $(tr).attr('data-id'), 3);
		},
		'style4': function(tr) {
			$(tr).addClass('mark_style4');
			markStyle('customer', $(tr).attr('data-id'), 4);
		},
		'style5': function(tr) {
			$(tr).addClass('mark_style5');
			markStyle('customer', $(tr).attr('data-id'), 5);
		},
		'remove': function(tr) {
			$(tr).removeClass();
			markStyle('customer', $(tr).attr('data-id'), 0);
		}
		<?php foreach ($stores as $store) { ?>
		 'store<?php echo $store['store_id']; ?>': function(tr){
			 window.open('<?php echo UA('sale/customer/login'); ?>&customer_id=' + $(tr).attr('data-id') + '&store_id=<?php echo $store['store_id']; ?>');
		 },
	    <?php } ?>
		'store0': function(tr) {
			window.open('<?php echo UA('sale/customer/login'); ?>&customer_id=' + $(tr).attr('data-id') + '&store_id=0');
		}
	}
});
<?php 
 $json = array();
 foreach($customer_groups as $customer_group) {
	$json[] = array('value' => $customer_group['customer_group_id'], 'label' => $customer_group['name']);
 }
 echo "var customer_groups = " . json_encode($json) . ";";
?>
$('.J_tablelist').listTable();
//--></script>
<?php echo $footer; ?> 